<template>
  <el-card shadow="never">
    <div slot="header">
      <span>加减分项目</span>
    </div>
    <e-table
      class="eval-table"
      ref="eTable"
      @getList="handleGetList"
      :tableData="tableData"
      :columns="columns"
      :loading="loading"
      :pageObj="null"
      :stripe="false"
    >
      <el-table-column
        slot="order"
        label="序号"
        type="index"
        :index="indexMethod"
        width="60"
        align="center"
      />
      <el-table-column slot="content" label="考评内容" align="center">
        <template
          slot-scope="scope"
        >{{ scope.row.parentName ? scope.row.parentName : scope.row.name }}</template>
      </el-table-column>
      <el-table-column slot="child" label="考评内容子项目" align="center">
        <template slot-scope="scope">{{ scope.row.parentName ? scope.row.name : null }}</template>
      </el-table-column>
      <!-- <el-table-column label="类型" slot="type" align="center" width="100">
        <template
          slot-scope="scope"
        >{{ scope.row.parentName? '基础项目' : (scope.row.moralityItemType === 1 ? '基础项目' : '加减分项目') }}</template>
      </el-table-column>-->
      <!-- <el-table-column slot="eval" width="100" label="自评分" align="center">
        <template slot-scope="scope">
          <el-input
            @input="handleInputGrade"
            v-model.number="scope.row.itemSelfScore"
            :min="0"
            :max="scope.row.basic"
            type="number"
          />
        </template>
      </el-table-column>-->
    </e-table>
  </el-card>
</template>

<script>
import { indexMethod } from '@/utils/util'

export default {
  data() {
    return {
      tableData: [],
      loading: false,
      columns: [
        {
          label: '考评项目名称',
          prop: 'evalItemName'
        },
        {
          label: '项目内容',
          prop: 'evalItemContent'
        },
        {
          label: '事件时间',
          prop: 'evalDate'
        },
        {
          label: '得分',
          prop: 'rewardValue'
        },
        // { slot: 'content' },
        // { slot: 'type' },
        // { slot: 'child' },
        {
          label: '基础分',
          prop: 'standard'
        }
      ],
      queryParam: {
        pageNo: 1,
        pageSize: 10
      }
    }
  },
  methods: {
    indexMethod,
    edit(arr) {
      this.tableData = [...arr]
    },
    // 父级拿数据
    getData() {
      const tablePost = this.tableData.every(v => v.itemSelfScore !== null)
      console.log('tablePost', tablePost)

      // 如果有一列分数未填，则调用不提交事件，不传输数据，阻断循环
      if (tablePost) {
        this.$emit('postData', 1, this.tableData)
      } else {
        this.$emit('notSubmit', 1)
      }
    },
    // handleInputGrade(e) {
    //   // console.log('e', e, this.tableData)
    //   let arr = []
    //   this.tableData.map(v => {
    //     arr.push(v.itemSelfScore)
    //   })
    //   this.$emit('countGrade', arr, 2)
    // },
    async handleGetList(param = {}) {
      this.loading = true
      this.queryParam = Object.assign(this.queryParam, param)
      const res = await checkList(this.queryParam)

      if (res && res.data.records.length > 0) {
        const {
          state,
          data: { records, total }
        } = res
        this.tableData = records
        this.total = total
      } else {
        this.tableData = []
        this.total = 1
      }
      this.loading = false
    }
  }
}
</script>

